package com.koron.css2.baseConfig.impl;

import com.koron.css2.ServerInterface;
import com.koron.css2.baseConfig.bean.ProcessTimeBean;
import com.koron.css2.baseConfig.mapper.ProcessTimeMapper;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.util.Constant;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

import java.util.Map;

public class ProcessTimeQuery implements ServerInterface{
	private Logger log = LogManager.getLogger(ProcessTimeQuery.class);
	@Override
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
		@SuppressWarnings("rawtypes")
        MessageBean<ProcessTimeBean> info = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "success", ProcessTimeBean.class);

        try {
            Map bean = JsonUtils.objectToPojo(req.getData(), Map.class);
            ProcessTimeMapper mapper = factory.getMapper(ProcessTimeMapper.class);
            if (StringUtils.isEmpty(bean.get("id").toString())) {
                return MessageBean.create(Constant.ILLEGAL_PARAMETER, "id为空", void.class);
            }
            ProcessTimeBean processTimeBean = mapper.query(bean.get("id").toString());
            info.setData(processTimeBean);
        } catch (Exception e) {
            info.setCode(Constant.MESSAGE_INT_FAIL);
            info.setDescription(e.getMessage());
            logger.error(e.getMessage(), e);
        }
        return info;
	}

}
